2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex1_avccRef.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
65 //******************************************************************************
66 #include "driverlib.h"
67 
68 void main (void)
69 {
70  //Stop WDT
71  WDT_A_hold(WDT_A_BASE);
72 
73  //Set P1.0 to output direction
74  GPIO_setAsOutputPin(
75  GPIO_PORT_P1,
76  GPIO_PIN0
77  );
78 
79  //Initialize the ADC10_A Module
80  /*
81  * Base Address for the ADC10_A Module
82  * Use internal ADC10_A bit as sample/hold signal to start conversion
83  * USE MODOSC 5MHZ Digital Oscillator as clock source
84  * Use default clock divider of 1
85  */
86  ADC10_A_init(ADC10_A_BASE,
87  ADC10_A_SAMPLEHOLDSOURCE_SC,
88  ADC10_A_CLOCKSOURCE_ADC10OSC,
89  ADC10_A_CLOCKDIVIDER_1);
90 
91  ADC10_A_enable(ADC10_A_BASE);
92 
93  /*
94  * Base Address for the ADC10_A Module
95  * Sample/hold for 16 clock cycles
96  * Do not enable Multiple Sampling
97  */
98  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
99  ADC10_A_CYCLEHOLD_16_CYCLES,
100  ADC10_A_MULTIPLESAMPLESDISABLE);
101 
102  //Configure the Memory Buffer
103  /*
104  * Base Address for the ADC10_A Module
105  * Use input A0
106  * Use positive reference of AVcc
107  * Use negative reference of AVss
108  */
109  ADC10_A_configureMemory(ADC10_A_BASE,
110  ADC10_A_INPUT_A0,
111  ADC10_A_VREFPOS_AVCC,
112  ADC10_A_VREFNEG_AVSS);
113 
114  //Enable the Memory Buffer Interrupt
115  ADC10_A_clearInterrupt(ADC10_A_BASE,
116  ADC10IFG0);
117  ADC10_A_enableInterrupt(ADC10_A_BASE,
118  ADC10IE0);
119 
120  for (;;)
121  {
122  __delay_cycles(5000);
123 
124  //Enable and Start the conversion
125  //in Single-Channel, Single Conversion Mode
126  ADC10_A_startConversion(ADC10_A_BASE,
127  ADC10_A_SINGLECHANNEL);
128 
129  //LPM0, ADC10_A_ISR will force exit
130  __bis_SR_register(CPUOFF + GIE);
131  __no_operation();
132 
133 
134  }
135 }
136 
137 // ADC10_A interrupt service routine
138 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
139 #pragma vector=ADC10_VECTOR
140 __interrupt
141 #elif defined(__GNUC__)
142 __attribute__((interrupt(ADC10_VECTOR)))
143 #endif
144 void ADC10_A_ISR (void) {
145 
146  switch (__even_in_range(ADC10IV,12)){
147  case 0: break; //No interrupt
148  case 2: break; //conversion result overflow
149  case 4: break; //conversion time overflow
150  case 6: break; //ADC10HI
151  case 8: break; //ADC10LO
152  case 10: break; //ADC10IN
153  case 12: //ADC10IFG0
154  //(Automatically clears ADC10IFG0 by reading memory buffer)
155  if (ADC10_A_getResults(ADC10_A_BASE) < 0x1FF){
156  //Clear P1.0 LED off
158  GPIO_PORT_P1,
159  GPIO_PIN0
160  );
161  } else {
162  //Set P1.0 LED on
164  GPIO_PORT_P1,
165  GPIO_PIN0
166  );
167  }
168 
169  //Clear CPUOFF bit from 0(SR)
171  break;
172  default: break;
173  }
174 }
void ADC10_A_ISR(void)
void main(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)